package edu.hcmus.sow.domain.security;

import org.springframework.security.acls.model.Sid;
import org.springframework.security.core.SpringSecurityCoreVersion;
import org.springframework.util.Assert;

public class GroupSid implements Sid {

   private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID;
   // ~ Instance fields
   // ================================================================================================

   private final String group;

   // ~ Constructors
   // ===================================================================================================

   public GroupSid(String group) {
      Assert.hasText(group, "Group required");
      this.group = group;
   }

   // ~ Methods
   // ========================================================================================================

   public boolean equals(Object object) {
      if ((object == null) || !(object instanceof GroupSid)) {
         return false;
      }

      // Delegate to getGroup() to perform actual comparison (both should be identical)
      return ((GroupSid) object).getGroup().equals(this.getGroup());
   }

   public int hashCode() {
      return this.getGroup().hashCode();
   }

   public String getGroup() {
      return group;
   }

   public String toString() {
      return "GroupSid[" + this.group + "]";
   }
}
